/*
 * @lc app=leetcode.cn id=367 lang=swift
 *
 * [367] 有效的完全平方数
 */

// @lc code=start
class Solution {
    func isPerfectSquare(_ num: Int) -> Bool {
        var left = 0, right = num
        while left <= right {
            let middle = (left + right) / 2
            if middle * middle > num {
                right = middle - 1
            } else if middle * middle < num {
                left = middle + 1
            } else {
                return true
            }
        }
        return false
    }
}
// @lc code=end

